package org.xsk.structure.linked;

/**
 * 双端链路
 */
public class DoubleEndedLink {
    private Link first;
    private Link last;

    public DoubleEndedLink() {
        first = null;
        last = null;
    }

    public boolean isEmpty(){
        return first == null;
    }

    public void insertFirst(long dd){
        Link link = new Link(dd);
        if (isEmpty()){
            last = link;
        }
        link.setNext(first);
        first = link;
    }

    public void insetLast(long dd){
        Link link = new Link(dd);
        if (isEmpty()){
            first = link;
        }else {
            last.setNext(link);
        }
        last = link;
    }
}
